package com.libre.auth.controller;

import com.libre.auth.entity.RolePermission;
import com.libre.auth.service.RolePermissionService;
import com.libre.common.base.BaseController;
import com.libre.common.enums.ResultEnum;
import com.libre.common.utils.ResultUtil;
import com.libre.common.vo.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* @description   用户角色
* @author        庞留杰
* @date          2022/01/01 17:46
* @version       V1.0
**/
@Slf4j
@RequestMapping("/rolePermission")
@RestController
public class RolePermissionController  extends BaseController {

    @Autowired
    private RolePermissionService service;

    @GetMapping("/findListByRoleId")
    public Result<List<RolePermission>> findListByRoleId(@ModelAttribute RolePermission rolePermission) {
        List<RolePermission> list = service.findListByRoleId(rolePermission);
        return new ResultUtil<List<RolePermission>>().setData(list);
    }

    @PostMapping("/save")
    public Result save(@RequestBody List<RolePermission> rolePermissions) {
        service.save(rolePermissions);
        return new ResultUtil().setSuccessMsg(ResultEnum.OK.getReasonPhraseCN());
    }

}
